#!/bin/bash
if [ $(whoami) != 'root' ]; then
  echo "You must be root to run this script."
  exit 1
fi

# Detect if the install media is running or not
if [ ! -d /tmp/frzr_root ]; then
  SUBVOL=""
  MOUNT_PATH=""
fi

CONNECTION=$1
EDID_FILE=$2

# Inject EDID override into initramfs
echo "Add EDID binary to mkinitcpio.conf"
cp -a ${MOUNT_PATH}/etc/mkinitcpio.conf ${MOUNT_PATH}/etc/mkinitcpio.conf.bak
sed -i s#FILES=\(\)#FILES=\(/lib/firmware/edid/${EDID_FILE}\)# ${MOUNT_PATH}/etc/mkinitcpio.conf

#  Update systemd-boot entries config
echo "Add EDID bin firmware to boot parameters"
$DQ_PATH/scripts/kernel-options-manager --append drm.edid_firmware=${CONNECTION}:edid/${EDID_FILE}
